package com.springmvc.study.controller;

import com.sun.media.sound.ModelDestination;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

/**
 * @author feifei
 * @create 2020-12-14-17:07
 */

@Controller
@RequestMapping("/user")
public class LoginController {

    @RequestMapping("/main")
    public String main(){
        return "main";
    }

    @RequestMapping("/goLogin")
    public String goLogin(){
        return "login";
    }


    @RequestMapping("/login")
    public String login(String username, String password, HttpSession session, Model model){
        // 用户的信息需要存在session中的
        session.setAttribute("userLoginInfo",username);
        model.addAttribute("name",username);
        System.out.println("-------------"+username);
        return "main";
    }

    @RequestMapping("/logout")
    public String logout(HttpSession httpSession){
        httpSession.removeAttribute("userLoginInfo");
        return "main";
    }
}